<template>
	<div class="alarmConfiguration zy-content">
		<!-- 工装与设备 -->
		<search :columns="searchData" @getSearch="getSearch(arguments)"></search>
		<div class="alarmConfiguration">
			<div class="list-layout mt16">
				<div class="btns clear">
					<span class="title">{{ $t('common.listInformation') }}</span>
					<Button @click="delFaultCodeShowClick" v-has="'moldLedgerBatchDelBtn'">{{ $t('common.batchDelete') }}</Button>
					<Button @click="exportTemplateClick" v-has="moldLedgerExport">{{ $t('common.Export') }}</Button>
					<Button @click="importExcelShow" v-has="moldLedgerImport">导入</Button>
					<Button @click="exportTemplate" v-has="moldLedgerDownload">{{ $t('common.Download') }}</Button>
					<Button @click="getTableColumns(columns)"> {{ handleContextMenuStatus ? $t('显示操作栏') : $t('隐藏操作栏') }}</Button>
				</div>
				<!-- 表格 -->
				<div class="tableContent">
					<Table
						class="resizable-table"
						border
						@on-column-width-resize="
							(a, b, c, d) => {
								onColumnWidthResize(a, b, c, d, 'orderAdjustmentDeviceInfo');
							}
						"
						:columns="orderAdjustmentDeviceInfoList"
						ellipsis
						ref="selection"
						stripe
						:data="dataArr"
						@on-selection-change="onSelectChange"
					>
						<template slot-scope="{ row }" slot="action">
							<span class="operationBtn" @click="checkDetail(row)">详情</span>
						</template>
					</Table>
				</div>
				<!-- 分页 -->
				<div class="pageWrap mt16">
					<pageLeftTitle :total="total" :selected="delIds.length" />
					<Page
						:total="total"
						:page-size="pageSize"
						:page-size-opts="pageSizeOption"
						:current="pageNum"
						@on-change="changePageNum"
						@on-page-size-change="changePageSize"
						show-sizer
						show-total
					/>
				</div>
			</div>
		</div>
		<commonModal ref="commonModal"></commonModal>
		<inputModal ref="inputModal"></inputModal>
	</div>
</template>
<script>
import { getList, deleteApi } from '@/api/system/equipmentAssociation.js';
import search from '@/components/curd/searchList.vue';
import inputModal from "@/components/modalTypes/inputModal.vue";
import commonModal from "@/components/modalTypes/commonModal.vue";
import fileDownload from 'js-file-download';
import toggleTableOperation from '@/mixins/toggleTableOperation';
export default {
	name: 'associationUser',
	components: { search ,inputModal,commonModal},
	mixins: [toggleTableOperation],
	data() {
		return {
			test: [],
			//一级搜索
			searchData: [
				{
					title: '领料任务单号',
					key: 'deviceNo',
				},
				{
					title: '物料编码',
					key: 'deviceName',
				},
				{
					title: '生产领料状态',
					key: 'deviceCategory',
					dicUrl: '/dms/faultCategory/dictList?name=设备类别',
					params: {
						value: 'value',
						label: 'value',
					},
					type: 'select',
				},
				{
					title: '工单任务号',
					key: 'isBindBox',
				},
				{
					title: '生产订单号',
					key: 'isBindBox',
				},
				{
					title: '工序编号/名称',
					key: 'deviceSpec',
				},
				{
					title: '工厂',
					key: 'installPosition',
					type: 'cascader',
					dicUrl: '/basic/organization/findListByToken?level=0',
					params: {
						label: 'name',
						value: 'code',
						children: 'children',
					},
				},
			],
			//一级table配置
			columns: [
				{
					key: 'selection',
					type: 'selection',
					width: 60,
					align: 'center',
				},
				{
					title: '领料任务单号',
					key: 'deviceNo',
					minWidth: 100,
					align: 'center',
					resizable: true,
					sortable: true,
					tooltip: true,
				},
				{
					title: '物料编号',
					key: 'deviceName',
					minWidth: 100,
					align: 'center',
					sortable: true,
					resizable: true,
					tooltip: true,
				},
				{
					title: '物料版本',
					key: 'deviceCategory',
					minWidth: 100,
					align: 'center',
					sortable: true,
					resizable: true,
					tooltip: true,
				},
				{
					title: '计划领料数量',
					key: 'deviceSpec',
					sortable: true,
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '实际领料数量',
					key: 'installPositionName',
					minWidth: 100,
					sortable: true,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '生产领料状态',
					key: 'isBindBox',
					sortable: true,
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '工单订单号',
					key: 'isBindBox',
					sortable: true,
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '生产订单号',
					key: 'isBindBox',
					sortable: true,
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '工序编号',
					key: 'isBindBox',
					sortable: true,
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '工序编号/工序名称',
					key: 'isBindBox',
					sortable: true,
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '操作',
					slot: 'action',
					fixed: 'right',
					minWidth: 180,
					align: 'center',
				},
			],
			loading: false,
			//三级搜索参数
			searchParams: {},

			//一级页面分页参数
			pageNum: 1,
			pageSize: 10,
			total: 0,

			dataArr: [],

			allCheck: false,

			delFaultCodeShowF: false, //是否显示删除弹窗
			pageSizeOption: [10, 20, 30, 40],
			delIds: [],
			selection: [],
			createByOptions: [],
		};
	},
	mounted() {
		// this.getTableColumnsWidth(this.columns);
		this.getTableColumnsWidth(this.columns, 'orderAdjustmentDeviceInfo');
		this.searchList();
	},
	methods: {
		reset() {
			this.searchParams = {};
			this.changeNum();
		},
		getSearch(params) {
			this.searchParams = JSON.parse(JSON.stringify(params[0]));
			this.pageNum = 1;
			this.searchList();
		},
		//分页
		changeNum() {
			this.pageNum = 1;
			this.searchList();
		},
		changePageSize(pageSize) {
			this.pageSize = pageSize;
			this.searchList();
		},
		changePageNum(val) {
			this.pageNum = val;
			this.searchList();
		},
    //  this.$refs.commonModal.showModal({
    //       title: "完成提醒",
    //       type: "sure",
    //       desc: "是否确认设备验收完成？",
    //       submit: () => {
    //         this.axios({
    //           method: "put",
    //           url: "/dms/deviceCheckAccept/pass",
    //           params: { id: row.id }
    //         }).then(res => {
    //           if (res.code === 200) {
    //             this.$Message.success(res.msg);
    //             this.searchList();
    //           } else {
    //             this.$Message.warning({
    //               content: res.msg,
    //               duration: 6,
    //               closable: true
    //             });
    //           }
    //         });
    //       }
    //     });
		//查询列表
		searchList() {
			let params = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
			};
			for (let key in this.searchParams) {
				if (this.searchParams[key]) {
					this.$set(params, key, this.searchParams[key]);
				}
			}
			getList(params).then((res) => {
				if (res.code === 200) {
					this.dataArr = res.data.records;
					this.total = res.data.total;
				} else {
					this.$Message.warning({
						content: res.msg,
						duration: 6,
						closable: true,
					});
				}
			});
		},
		checkDetail(row) {
			this.$router.push({
				path: '/planManage/materialRequisition/detail',
				query: {
					// status: "add",
					deviceCode: row.deviceNo,
				},
			});
		},
		deleteOk() {
			this.loading = true;
			let params = { deviceIdList: this.delIds1, moldId: this.id };
			deleteApi(params).then((res) => {
				this.loading = false;
				if (res.code === 200) {
					this.changeNum1();
					this.$Message.success('删除成功');
					this.$refs.selection.selectAll(false);
					this.delFaultCodeShowF = false;
				} else {
					this.$Message.warning({
						content: res.msg,
						duration: 6,
						closable: true,
					});
				}
			});
		},
		//导出
		exportTemplateClick() {
			let params = {
				...this.searchParams,
			};
			const filName = '物料分类定义';
			this.axios({
				method: 'get',
				// url: 'dms/material/template',
				responseType: 'blob',
			}).then((res) => {
				fileDownload(res, filName + '.xlsx');
			});
		},
	},
};
</script>

<style scoped lang="scss">
.ivu-input-number {
	width: -webkit-fill-available;
}

.btn-box {
	padding: 8px 5px !important;
}
</style>
